<template>
    <div class="box">
        <header class="header">
            <van-search show-action placeholder="请输入搜索关键词">
                <template #left>
                    <van-icon name="arrow-left" size="20" @click="$router.back()" />
                </template>
                <template #action>
                    <div @click="onClickButton">搜索</div>
                </template>
            </van-search>
        </header>
        <div class="content">
            <div class="sidebar">
                <van-sidebar v-model="active" class="left" @change="onChange">
                    <van-sidebar-item title="手机数码" />
                    <van-sidebar-item title="礼品鲜花" />
                    <van-sidebar-item title="男装女装" />
                </van-sidebar>
                <ul class="right">
                    <h3>{{ list[0] && list[0].classify }}</h3>
                    <div class="list">
                        <li v-for="item in list" :key="item.id">
                            <van-image lazy-load :src="item.image" />
                            <p>{{ item.title }}</p>
                        </li>
                    </div>
                </ul>
            </div>
        </div>
    </div>
</template>
<script setup>
import { ref, onMounted } from 'vue';
import request from "@/utils/request"
const active = ref(0)
const list = ref([])
const onChange = (index) => {
    console.log(index)
    const arr = ['手机数码', '礼品鲜花', '男装女装']
    request.get('/kind', { params: { key: arr[index] } }).then(res => {
        if (res.data.code == 200) {
            list.value = res.data.data
        }
    })
}
onMounted(() => {
    onChange(active.value)
})
</script>
<style lang="scss" scoped>
.sidebar {
    display: flex;

    .left {
        width: 100px;
        position: fixed;
    }

    .right {
        margin-left: 100px;

        h3 {
            margin: 10px;
        }

        .list {
            display: flex;
            flex-wrap: wrap;

            li {
                width: 30%;
                margin: 1.5%
            }
        }
    }
}
</style>